package com.yonyou.brigade.order_center.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.order_center.model.*;
import com.yonyou.brigade.util.HttpClientUtil;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class OrderConvert {

    private static String URL = "https://ybz.yonyoucloud.com/open/brigade/apply/findApplyByPks";

    public static String fromTypeName(String fromType) {
        String result = fromType;
        switch (fromType) {
            case "rtpnr":
                result = "友商旅";
                break;
            case "ctripBC":
                result = "携程大客户";
                break;
            case "clyh":
                result = "差旅壹号";
                break;
            case "tujia":
                result = "途家";
                break;
            case "tuniu":
                result = "途牛";
                break;
            case "ctripSME":
                result = "携程商旅通";
                break;
            case "zteitc":
                result = "中兴";
                break;
            case "fanscar":
                result = "泛嘉国际";
                break;
            case "didi":
                result = "滴滴";
                break;
            case "meiya":
                result = "美亚";
                break;
            case "HCHoliday":
                result = "花城";
                break;
            default:
                break;
        }
        return  result;
    }

    public static String orderTypeName(String orderType) {
        String result = orderType;
        switch (orderType) {
            case "N":
                result = "正常单";
                break;
            case "T":
                result = "退票单";
                break;
            case "G":
                result = "改签订单";
                break;
            case "C":
                result = "差价";
                break;
            default:
                break;
        }
        return  result;
    }

    public static String isDomicName(String isDomc) {
        String result = isDomc;
        switch (isDomc) {
            case "D":
                result = "国内";
                break;
            case "I":
                result = "国际";
                break;
            default:
                break;

        }
        return  result;
    }

    public static String flightWay(BriFlightInfoDTO briFlightInfoDTO) {
        String result = "";
        if(briFlightInfoDTO != null) {
            if ("友商旅".equals(briFlightInfoDTO.getFromType()) && briFlightInfoDTO.getBoardPointName() != null && briFlightInfoDTO.getBoardPointAirPortName() != null
                    && briFlightInfoDTO.getOffPointName() != null && briFlightInfoDTO.getOffPointAirPortName() != null
                    && briFlightInfoDTO.getBoardPointAirPortName().length() >= briFlightInfoDTO.getBoardPointName().length()
                    && briFlightInfoDTO.getOffPointAirPortName().length() >= briFlightInfoDTO.getOffPointName().length()){
                String fromPlace = briFlightInfoDTO.getBoardPointAirPortName();
                String toPlace = briFlightInfoDTO.getOffPointAirPortName();
                if (!(briFlightInfoDTO.getBoardPointName().equals(briFlightInfoDTO.getBoardPointAirPortName().substring(0,briFlightInfoDTO.getBoardPointName().length())))){
                    fromPlace = briFlightInfoDTO.getBoardPointName() + briFlightInfoDTO.getBoardPointAirPortName();
                }
                if (!(briFlightInfoDTO.getOffPointName().equals(briFlightInfoDTO.getOffPointAirPortName().substring(0,briFlightInfoDTO.getOffPointName().length())))){
                    toPlace = briFlightInfoDTO.getOffPointName()+briFlightInfoDTO.getOffPointAirPortName();
                }
                result = fromPlace + "=>" + toPlace;
            } else {
                result = briFlightInfoDTO.getBoardPointName()+briFlightInfoDTO.getBoardPointAirPortName() + "=>" + briFlightInfoDTO.getOffPointName()+briFlightInfoDTO.getOffPointAirPortName();
            }
        }
        return  result;
    }

    public static String psgTypeName(String psgType) {
        String result = psgType;
        switch (psgType) {
            case "ADT":
                result = "成人";
                break;
            case "INF":
                result = "婴儿";
                break;
            case "CHD":
                result = "儿童";
                break;
            case "UM":
                result = "无人陪伴儿童";
                break;
            default:
                break;
        }
        return result;
    }

    public static String flightDateTime(String departureDate,String departureTime) {
        String result = "";
        if(departureDate != null && departureTime != null && departureDate != "" && departureTime != "") {
            result = departureDate.trim()+" "+departureTime.trim();
        }
        return result;
    }

    public static String flightEndDateTime(String arriveDate,String arriveTime) {
        String result = "";
        if(arriveDate != null && arriveTime != null && arriveDate != "" && arriveTime != "") {
            result=arriveDate.trim()+" "+arriveTime.trim();
        }
        return result;
    }

    public static String hotelOrderStatusName(String orderStatus) {
        String result = orderStatus;
        switch (orderStatus) {
            case "WS":
                result = "待提交";
                break;
            case "WQ":
                result = "待确认";
                break;
            case "WA":
                result = "等待审批";
                break;
            case "WR":
                result = "审批已拒绝";
                break;
            case "10":
                result = "待确认";
                break;
            case "11":
                result = "取消";
                break;
            case "12":
                result = "已确认(现付)/待确认(预付)";
                break;
            case "13":
                result = "入住中";
                break;
            case "14":
                result = "正常离店";
                break;
            case "15":
                result = "提前离店";
                break;
            case "16":
                result = "NoShow";
                break;
            case "17":
                result = "已支付";
                break;
            case "18":
                result = "变更取消";
                break;
            case "19":
                result = "确认失败已退款";
                break;
            case "20":
                result = "已确认(预付)";
                break;
            case "25":
                result = "已成交";
                break;
            case "26":
                result = "未提交";
                break;
            default:
                break;
        }
        return  result;
    }

    public static String flightOrderStatusName(String orderStatus) {
        String result = orderStatus;
        switch (orderStatus) {
            case "WC":
                result = "未处理";
                break;
            case "CL":
                result = "处理中";
                break;
            case "QX":
                result = "已取消";
                break;
            case "QT":
                result = "全部退票";
                break;
            case "BT":
                result = "部分退票";
                break;
            case "CJ":
                result = "已成交";
                break;
            case "WS":
                result = "待提交";
                break;
            case "WQ":
                result = "待确认";
                break;
            case "WA":
                result = "等待审批";
                break;
            case "WR":
                result = "审批已拒绝";
                break;
            case "NW":
                result = "未支付";
                break;
            case "WP":
                result = "待出票";
                break;
            case "NP":
                result = "出票完成";
                break;
            case "NR":
                result = "退回";
                break;
            case "TI":
                result = "退票处理中";
                break;
            case "TP":
                result = "退票完成";
                break;
            case "HP":
                result = "有退票";
                break;
            case "TE":
                result = "异常状态";
                break;
            default:
                break;
        }
        return  result;
    }

    public static String trainOrderStatusName(String orderStatus) {
        String result = orderStatus;
        switch (orderStatus) {
            case "WS":
                result = "待提交";
                break;
            case "WA":
                result = "等待审批";
                break;
            case "WR":
                result = "审批已拒绝";
                break;
            case "AT":
                result = "新单待确认";
                break;
            case "NW":
                result = "新订单待支付";
                break;
            case "PY":
                result = "已支付";
                break;
            case "TP":
                result = "已出票";
                break;
            case "RW":
                result = "出票失败待退款";
                break;
            case "RP":
                result = "出票失败已退款";
                break;
            case "CO":
                result = "已取消";
                break;
            case "AR":
                result = "申请退票";
                break;
            case "PR":
                result = "退票(退款)部分成功";
                break;
            case "FR":
                result = "退票成功";
                break;
            case "RR":
                result = "退票失败";
                break;
            case "GA":
                result = "改签申请";
                break;
            case "GE":
                result = "改签失败";
                break;
            case "GK":
                result = "座位确认";
                break;
            case "GO":
                result = "取消改签";
                break;
            case "GT":
                result = "改签成功";
                break;
            case "GR":
                result = "改签退票单(未退款)";
                break;
            case "GD":
                result = "改签退票单结束(已退款)";
                break;
            case "N":
                result = "未提交";
                break;
            case "WP":
                result = "待支付";
                break;
            case "PP":
                result = "支付处理中";
                break;
            case "PF":
                result = "支付失败";
                break;
            case "WU":
                result = "待授权";
                break;
            case "UR":
                result = "授权失败";
                break;
            case "WT":
                result = "待出票";
                break;
            case "TI":
                result = "购票中";
                break;
            case "TD":
                result = "已购票";
                break;
            case "TF":
                result = "出票失败";
                break;
            default:
                break;
        }
        return  result;
    }

    public static String payTypeName(String payType) {
        String result = payType;
        switch (payType) {
            case "Prepay":
                result = "预付(企业支付)";
                break;
            case "Selfpay":  //目前还不确定
                result = "现付(个人支付)";
                break;
            case "Monthlypay":
                result = "月结";
                break;
            case "CASH":
                result = "现金";
                break;
            case "ACCNT":
                result = "公司账户支付";
                break;
            case "TMPAY":
                result = "礼品卡支付";
                break;
            case "CCARD":
                result = "信用卡支付";
                break;
            default:
                break;
        }
        return  result;
    }

    public static String hotelPaymentTypeName(String paymentType) {
        String result = paymentType;
        switch (paymentType) {
            case "Prepay":
                result = "预付";
                break;
            case "Selfpay":  //目前还不确定
                result = "现付";
                break;
            case "Monthlypay":
                result = "月结";
                break;
            case "CASH":
                result = "现金";
                break;
            case "ACCNT":
                result = "公司账户支付";
                break;
            case "TMPAY":
                result = "礼品卡支付";
                break;
            case "CCARD":
                result = "信用卡支付";
                break;
            case "QK":
                result = "欠款";
                break;
            case "ZH":
                result = "账户";
                break;
            case "XJ":
                result = "现金";
                break;
            case "WZ":
                result = "网支";
                break;
            default:
                break;
        }
        return  result;
    }

    private static String flightPayTypeName(String payType) {
        String result = payType;
        switch (payType) {
            case "Prepay":
                result = "预付(企业支付)";
                break;
            case "Selfpay":  //目前还不确定
                result = "现付(个人支付)";
                break;
            case "Monthlypay":
                result = "月结";
                break;
            case "CASH":
                result = "现金";
                break;
            case "ACCNT":
                result = "公司账户支付";
                break;
            case "TMPAY":
                result = "礼品卡支付";
                break;
            case "CCARD":
                result = "信用卡支付";
                break;
            case "CHECK":
                result = "支票支付";
                break;
            case "UNPAY":
                result = "银联在线支付";
                break;
            case "PCARD":
                result = "手机支付";
                break;
            case "APPAY":
                result = "AirPlus支付";
                break;
            case "DQPAY":
                result = "储蓄卡快捷";
                break;
            default:
                break;
        }
        return  result;
    }

    private static String flightPaymentTypeName(String paymentType) {
        String result = paymentType;
        switch (paymentType){
            case "Selfpay":
                result = "现付";
                break;
            case "Monthlypay":
                result = "月结";
                break;
            case "QK":
                result = "欠款";
                break;
            case "ZH":
                result = "账户";
                break;
            case "XJ":
                result = "现金";
                break;
            case "WZ":
                result = "网支";
                break;
            case "CCARD":
                result = "信用卡支付";
                break;
            case "CHECK":
                result = "支票支付";
                break;
            case "UNPAY":
                result = "银联在线支付";
                break;
            case "ACCNT":
                result = "公司账户支付";
                break;
            case "PCARD":
                result = "手机支付";
                break;
            case "TMPAY":
                result = "礼品卡支付";
                break;
            case "CASH":
                result = "现金支付";
                break;
            case "APPAY":
                result = " AirPlus支付 ";
                break;
            case "DQPAY":
                result = "储蓄卡快捷";
                break;
            case "ALPAY":
                result = "支付宝";
                break;
            case "WSCAN":
                result = "微信";
                break;
            case "ABPAY":
                result = "农行网银";
                break;
            case "BCPAY":
                result = "中行网银";
                break;
            case "CBPAY":
                result = "建行网银";
                break;
            case "CMPAY":
                result = "招行网银";
                break;
            case "IBPAY":
                result = "工行网银";
                break;
            case "PSPAY":
                result = "邮储网银";
                break;
            case "PDPAY":
                result = "浦发网银";
                break;
            case "CTPAY":
                result = "交通网银";
                break;
            case "MAPAY":
                result = "手机支付宝";
                break;
        }
        return result;
    }

    public static String psgNums(String psgName) {
        String result = "";
        int count = 0;
        if(psgName != null) {
            char[] chars = psgName.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if (",".equals(chars[i])) {
                    count++;
                }
            }
            result = String.valueOf(count+1);
        }
        return result;
    }

    private static String createTime(String createTime) {
        String result = "";
        if (createTime != null && createTime != "") {
            result = createTime.trim();
            char[] chars = result.toCharArray();
            String date = String.copyValueOf(chars, 0, 10);
            String time = String.copyValueOf(chars,11,8);
            result = date + " " + time;
        }
        return result;
    }

    private static String orderTime(String orderTime) {
        String result = "";
        if (orderTime != null && orderTime != "") {
            result = orderTime.trim();
            char[] chars = result.toCharArray();
            String date = String.copyValueOf(chars, 0, 10);
            String time = String.copyValueOf(chars,11,8);
            result = date + " " + time;
        }
        return result;
    }

    public static String fromDateTime(String trainDate,String fromTime) {
        String result = "";
        if(trainDate != null && fromTime != null && trainDate != "" && fromTime != "") {
            result = trainDate.trim()+" "+fromTime.trim();
        }
        return result;
    }

    public static String toDateTime(String toDate,String toTime) {
        String result = "";
        if(toDate != null && toTime != null && toDate != "" && toTime != "") {
            result = toDate.trim()+" "+toTime.trim();
        }
        return result;
    }

    public static String trainAuthStatusName(String authStatus){
        String result = authStatus;
        switch (authStatus) {
            case "0":
                result = "";
                break;
            case "NA":
                result = "未知";
                break;
            case "T":
                result = "授权通过";
                break;
            case "A":
                result = "无需授权";
                break;
            case "F":
                result = "授权否决";
                break;
            case "C":
                result = "授权终止";
                break;
            case "W1":
                result = "等待1次授权";
                break;
            case "W2":
                result = "等待2次授权";
                break;
            default:
                break;
        }
        return result;
    }

    public static String hotelAuthStatusName(String authStatus){
        String result = authStatus;
        switch (authStatus) {
            case "0":
                result = "";
                break;
            default:
                break;
        }
        return result;
    }

    public static String bxStatusName(String bxStatus){
        if (bxStatus == null){
            return "未报销";
        }
        String result = bxStatus;
        switch (bxStatus) {

            case "1":
                result = "报销中";
                break;
            case "2":
                result = "已报销";
                break;
            case "3":
                result = "已记账";
                break;
            default:
                result = "未报销";
                break;
        }
        return result;
    }

    private static String isNoteName(String isNote) {
        String result = isNote;
        switch (isNote) {
            case "0":
                result = "未生成记事";
                break;
            case "1":
                result = "已生成记事";
                break;
            default:
                break;
        }
        return result;
    }

    private static String carOrderStatusName(String orderStatus) {
        String result = orderStatus;
        switch (orderStatus) {
            case "0":
                result = "其他";
                break;
            case "1":
                result = "待支付（行程未结束）";
                break;
            case "2":
                result = "已支付";
                break;
            case "3":
                result = "已退款";
                break;
            case "4":
                result = "已取消";
                break;
            case "7":
                result = "部分退款";
                break;
            case "10":
                result = "等待应答";
                break;
            case "11":
                result = "已应答/等待接驾";
                break;
            case "12":
                result = "司机已到达";
                break;
            case "13":
                result = "行程中/正在服务";
                break;
            case "14":
                result = "异常结束（已支付）";
                break;
            case "15":
                result = "行程结束（未支付）";
                break;
            default:
                break;
        }
        return result;
    }

    private static String publicOrPrivateName(String publicOrPrivate) {
        String result = publicOrPrivate;
        switch (publicOrPrivate) {
            case "1":
                result = "因公";
                break;
            case "2":
                result = "因私";
                break;
            default:
                break;
        }
        return result;
    }

    private static String carTypeName(String type) {
        String result = type;
        switch (type) {
            case "0":
                result = "实时";
                break;
            case "1":
                result = "预约";
                break;
            default:
                break;
        }
        return result;
    }

    public static BriFlightInfoDTO perfactFlightDTO(BriFlightInfoDTO briFlightInfoDTO) {
        if(briFlightInfoDTO == null) {
            return  null;
        }
        briFlightInfoDTO.setFromType(fromTypeName(briFlightInfoDTO.getFromType()));
        briFlightInfoDTO.setOrderType(orderTypeName(briFlightInfoDTO.getOrderType()));
        briFlightInfoDTO.setIsDomc(isDomicName(briFlightInfoDTO.getIsDomc()));
        briFlightInfoDTO.setFlightWay(flightWay(briFlightInfoDTO));
        briFlightInfoDTO.setPsgType(psgTypeName(briFlightInfoDTO.getPsgType()));
        briFlightInfoDTO.setFlightDateTime(flightDateTime( briFlightInfoDTO.getDepartureDate(),briFlightInfoDTO.getDepartureTime()));
        briFlightInfoDTO.setFlightEndDateTime(flightEndDateTime(briFlightInfoDTO.getArriveDate(),briFlightInfoDTO.getArriveTime()));
        briFlightInfoDTO.setPayType(flightPayTypeName(briFlightInfoDTO.getPayType()));
        briFlightInfoDTO.setPaymentType(flightPaymentTypeName(briFlightInfoDTO.getPaymentType()));
        briFlightInfoDTO.setBxStatus(bxStatusName(briFlightInfoDTO.getBxStatus()));
        dealWithApplyFlight(briFlightInfoDTO.getTenant(), briFlightInfoDTO);
        return briFlightInfoDTO;
    }
    /**
     * 通过调用ybz服务为申请单相关字段赋值
     * @param tenant
     * @param briFlightInfoDTO
     */
    private static void dealWithApplyFlight(String tenant, BriFlightInfoDTO briFlightInfoDTO) {
//        int page = 1;
//        boolean flag = true;
//        List<String> applyIdList = new ArrayList<>();
        if (!StringUtils.isEmpty(briFlightInfoDTO.getRelateYBZID())) {
//            HashMap<String, Object> paramMap = new HashMap<>();
//            applyIdList.clear();
//            applyIdList.add(briFlightInfoDTO.getRelateYBZID());
//            paramMap.put("tenant", tenant);
//            paramMap.put("pagenum", 10);
//            paramMap.put("pks", applyIdList);
//            //暂时没传电话
//            String phone = "";
//            while (flag) {
//                paramMap.put("page", page++);
//                HashMap<String, String> headers = new HashMap<>();
//                headers.put("Content-Type", "application/json");
//                String res = HttpClientUtil.post(URL + "?phone=" + phone + "&loginType=1&tenantId=" + tenant, headers, null, JSON.toJSONString(paramMap));
//                JSONObject resObject = JSON.parseObject(res);
//                if (resObject.getBoolean("success") && "1".equals(resObject.getString("code"))) {
//                    if (resObject.getJSONArray("data") != null && !resObject.getJSONArray("data").isEmpty()) {
//                        for (int i = 0; i < resObject.getJSONArray("data").size(); i++) {
//                            JSONObject data = resObject.getJSONArray("data").getJSONObject(i);
//                            if (data.getBoolean("success")) {
//                                JSONArray heads = data.getJSONArray("head");
//                                if (heads != null) {
//                                    for (Object head : heads) {
//                                        JSONObject headJsonObject = (JSONObject) head;
//                                        if (BriFlightOrder.ASSUME_ORG.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            //若能获取到翻译结果，则显示翻译结果；若获取不到，则显示保存时的name值
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briFlightInfoDTO.setAssumeOrg(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithAssumeOrgFlight(briFlightInfoDTO);
//                                            }
//                                        }
//                                        if (BriFlightOrder.ASSUME_DEPT.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briFlightInfoDTO.setAssumeDept(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithAssumeDeptFlight(briFlightInfoDTO);
//                                            }
//                                        }
//                                        if (BriFlightOrder.COST_PROJECT.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briFlightInfoDTO.setCostProject(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithCostProjectFlight(briFlightInfoDTO);
//                                            }
//                                        }
//                                        if (BriFlightOrder.APPLY_USER.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briFlightInfoDTO.setApplyUser(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithApplyUserFlight(briFlightInfoDTO);
//                                            }
//                                        }
//                                        if (BriFlightOrder.COMPANION.equals(headJsonObject.getString("source_code"))) {
//                                            if (headJsonObject.get("source_value") instanceof String && !StringUtils.isEmpty(headJsonObject.getString("source_value"))) {
//                                                briFlightInfoDTO.setCompanion(headJsonObject.getString("source_value"));
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    } else {
//                        dealWithAssumeOrgFlight(briFlightInfoDTO);
//                        dealWithAssumeDeptFlight(briFlightInfoDTO);
//                        dealWithCostProjectFlight(briFlightInfoDTO);
//                        dealWithApplyUserFlight(briFlightInfoDTO);
//                    }
//                    //最后一页跳出循环
//                    if (resObject.getInteger("totalPage") < page) {
//                        flag = false;
//                    }
//                } else {
//                    flag = false;
                    dealWithAssumeOrgFlight(briFlightInfoDTO);
                    dealWithAssumeDeptFlight(briFlightInfoDTO);
                    dealWithCostProjectFlight(briFlightInfoDTO);
                    dealWithApplyUserFlight(briFlightInfoDTO);
//                }
//            }
        }
    }

    private static void dealWithApplyUserFlight(BriFlightInfoDTO briFlightInfoDTO) {
        if (!StringUtils.isEmpty(briFlightInfoDTO.getApplyUser()) && briFlightInfoDTO.getApplyUser().contains(",")) {
            String[] split = briFlightInfoDTO.getApplyUser().split(",");
            if (split.length > 1) {
                briFlightInfoDTO.setApplyUser(split[1]);
            }
        }
    }

    private static void dealWithCostProjectFlight(BriFlightInfoDTO briFlightInfoDTO) {
        if (!StringUtils.isEmpty(briFlightInfoDTO.getCostProject()) && briFlightInfoDTO.getCostProject().contains(",")) {
            String[] split = briFlightInfoDTO.getCostProject().split(",");
            if (split.length > 1) {
                briFlightInfoDTO.setCostProject(split[1]);
            }
        }
    }

    private static void dealWithAssumeDeptFlight(BriFlightInfoDTO briFlightInfoDTO) {
        if (!StringUtils.isEmpty(briFlightInfoDTO.getAssumeDept()) && briFlightInfoDTO.getAssumeDept().contains(",")) {
            String[] split = briFlightInfoDTO.getAssumeDept().split(",");
            if (split.length > 1) {
                briFlightInfoDTO.setAssumeDept(split[1]);
            }
        }
    }

    private static void dealWithAssumeOrgFlight(BriFlightInfoDTO briFlightInfoDTO) {
        if (!StringUtils.isEmpty(briFlightInfoDTO.getAssumeOrg()) && briFlightInfoDTO.getAssumeOrg().contains(",")) {
            String[] split = briFlightInfoDTO.getAssumeOrg().split(",");
            if (split.length > 1) {
                briFlightInfoDTO.setAssumeOrg(split[1]);
            }
        }
    }


    public static BriHotelRoomDTO perfactHotelRoomDTO(BriHotelRoomDTO briHotelRoomDTO) {
        if(briHotelRoomDTO == null) {
            return  null;
        }
        briHotelRoomDTO.setFromType(fromTypeName(briHotelRoomDTO.getFromType()));
        briHotelRoomDTO.setIsDomc(isDomicName(briHotelRoomDTO.getIsDomc()));
        briHotelRoomDTO.setStatusType(orderTypeName(briHotelRoomDTO.getStatusType()));
        briHotelRoomDTO.setOrderStatus(hotelOrderStatusName(briHotelRoomDTO.getOrderStatus()));
        briHotelRoomDTO.setPayType(payTypeName(briHotelRoomDTO.getPayType()));//产品定为Prepay和Selfpay
        briHotelRoomDTO.setCreateTime(createTime(briHotelRoomDTO.getCreateTime()));
        briHotelRoomDTO.setPaymentType(hotelPaymentTypeName(briHotelRoomDTO.getPaymentType()));//中航易购传回来的值有问题，跟paytype是一样的Prepay和Selfpay
        briHotelRoomDTO.setInNights(String.valueOf(Integer.parseInt(briHotelRoomDTO.getInDays())*Integer.parseInt(briHotelRoomDTO.getRoomNums())));
        briHotelRoomDTO.setPsgNums(psgNums(briHotelRoomDTO.getPsgName()));
        briHotelRoomDTO.setBxStatus(bxStatusName(briHotelRoomDTO.getBxStatus()));
        briHotelRoomDTO.setAuthStatus(hotelAuthStatusName(briHotelRoomDTO.getAuthStatus()));
        dealWithApplyHotel(briHotelRoomDTO.getTenant(), briHotelRoomDTO);
        return briHotelRoomDTO;
    }

    private static void dealWithApplyHotel(String tenant, BriHotelRoomDTO briHotelRoomDTO) {
//        int page = 1;
//        boolean flag = true;
//        List<String> applyIdList = new ArrayList<>();
        if (!StringUtils.isEmpty(briHotelRoomDTO.getRelateYBZID())) {
//            HashMap<String, Object> paramMap = new HashMap<>();
//            applyIdList.clear();
//            applyIdList.add(briHotelRoomDTO.getRelateYBZID());
//            paramMap.put("tenant", tenant);
//            paramMap.put("pagenum", 10);
//            paramMap.put("pks", applyIdList);
//            //暂时没传电话
//            String phone = "";
//            while (flag) {
//                paramMap.put("page", page++);
//                HashMap<String, String> headers = new HashMap<>();
//                headers.put("Content-Type", "application/json");
//                String res = HttpClientUtil.post(URL + "?phone=" + phone + "&loginType=1&tenantId=" + tenant, headers, null, JSON.toJSONString(paramMap));
//                JSONObject resObject = JSON.parseObject(res);
//                if (resObject.getBoolean("success") && "1".equals(resObject.getString("code"))) {
//                    if (resObject.getJSONArray("data") != null && !resObject.getJSONArray("data").isEmpty()) {
//                        for (int i = 0; i < resObject.getJSONArray("data").size(); i++) {
//                            JSONObject data = resObject.getJSONArray("data").getJSONObject(i);
//                            if (data.getBoolean("success")) {
//                                JSONArray heads = data.getJSONArray("head");
//                                if (heads != null) {
//                                    for (Object head : heads) {
//                                        JSONObject headJsonObject = (JSONObject) head;
//                                        if (BriHotelOrder.ASSUME_ORG.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            //若能获取到翻译结果，则显示翻译结果；若获取不到，则显示保存时的name值
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briHotelRoomDTO.setAssumeOrg(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithAssumeOrgHotel(briHotelRoomDTO);
//                                            }
//                                        }
//                                        if (BriHotelOrder.ASSUME_DEPT.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briHotelRoomDTO.setAssumeDept(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithAssumeDeptHotel(briHotelRoomDTO);
//                                            }
//                                        }
//                                        if (BriHotelOrder.COST_PROJECT.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briHotelRoomDTO.setCostProject(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithCostProjectHotel(briHotelRoomDTO);
//                                            }
//                                        }
//                                        if (BriHotelOrder.APPLY_USER.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briHotelRoomDTO.setApplyUser(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithApplyUserHotel(briHotelRoomDTO);
//                                            }
//                                        }
//                                        if (BriHotelOrder.COMPANION.equals(headJsonObject.getString("source_code"))) {
//                                            if (headJsonObject.get("source_value") instanceof String && !StringUtils.isEmpty(headJsonObject.getString("source_value"))) {
//                                                briHotelRoomDTO.setCompanion(headJsonObject.getString("source_value"));
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    } else {
//                        dealWithAssumeOrgHotel(briHotelRoomDTO);
//                        dealWithAssumeDeptHotel(briHotelRoomDTO);
//                        dealWithCostProjectHotel(briHotelRoomDTO);
//                        dealWithApplyUserHotel(briHotelRoomDTO);
//                    }
//                    //最后一页跳出循环
//                    if (resObject.getInteger("totalPage") < page) {
//                        flag = false;
//                    }
//                } else {
//                    flag = false;
                    dealWithAssumeOrgHotel(briHotelRoomDTO);
                    dealWithAssumeDeptHotel(briHotelRoomDTO);
                    dealWithCostProjectHotel(briHotelRoomDTO);
                    dealWithApplyUserHotel(briHotelRoomDTO);
//                }
//            }
        }
    }

    private static void dealWithApplyUserHotel(BriHotelRoomDTO briHotelRoomDTO) {
        if (!StringUtils.isEmpty(briHotelRoomDTO.getApplyUser()) && briHotelRoomDTO.getApplyUser().contains(",")) {
            String[] split = briHotelRoomDTO.getApplyUser().split(",");
            if (split.length > 1) {
                briHotelRoomDTO.setApplyUser(split[1]);
            }
        }
    }

    private static void dealWithCostProjectHotel(BriHotelRoomDTO briHotelRoomDTO) {
        if (!StringUtils.isEmpty(briHotelRoomDTO.getCostProject()) && briHotelRoomDTO.getCostProject().contains(",")) {
            String[] split = briHotelRoomDTO.getCostProject().split(",");
            if (split.length > 1) {
                briHotelRoomDTO.setCostProject(split[1]);
            }
        }
    }

    private static void dealWithAssumeDeptHotel(BriHotelRoomDTO briHotelRoomDTO) {
        if (!StringUtils.isEmpty(briHotelRoomDTO.getAssumeDept()) && briHotelRoomDTO.getAssumeDept().contains(",")) {
            String[] split = briHotelRoomDTO.getAssumeDept().split(",");
            if (split.length > 1) {
                briHotelRoomDTO.setAssumeDept(split[1]);
            }
        }
    }

    private static void dealWithAssumeOrgHotel(BriHotelRoomDTO briHotelRoomDTO) {
        if (!StringUtils.isEmpty(briHotelRoomDTO.getAssumeOrg()) && briHotelRoomDTO.getAssumeOrg().contains(",")) {
            String[] split = briHotelRoomDTO.getAssumeOrg().split(",");
            if (split.length > 1) {
                briHotelRoomDTO.setAssumeOrg(split[1]);
            }
        }
    }


    public static BriTrainTicketDTO perfactTrainDTO(BriTrainTicketDTO briTrainTicketDTO) {
        if(briTrainTicketDTO == null) {
            return  null;
        }
        briTrainTicketDTO.setFromType(fromTypeName(briTrainTicketDTO.getFromType()));
        briTrainTicketDTO.setOrderType(orderTypeName(briTrainTicketDTO.getOrderType()));
        briTrainTicketDTO.setOrderStatus(trainOrderStatusName(briTrainTicketDTO.getOrderStatus()));
        briTrainTicketDTO.setFromDateTime(fromDateTime(briTrainTicketDTO.getTrainDate(),briTrainTicketDTO.getFromTime()));
        briTrainTicketDTO.setToDateTime(toDateTime(briTrainTicketDTO.getToDate(),briTrainTicketDTO.getToTime()));
        briTrainTicketDTO.setOrderTime(orderTime(briTrainTicketDTO.getOrderTime()));
        briTrainTicketDTO.setAuthStatus(trainAuthStatusName(briTrainTicketDTO.getAuthStatus()));
        briTrainTicketDTO.setBxStatus(bxStatusName(briTrainTicketDTO.getBxStatus()));
        briTrainTicketDTO.setPayType(payTypeName(briTrainTicketDTO.getPayType()));
        dealWithApplyTrain(briTrainTicketDTO.getTenant(), briTrainTicketDTO);
        return briTrainTicketDTO;
    }

    private static void dealWithApplyTrain(String tenant, BriTrainTicketDTO briTrainTicketDTO) {
//        int page = 1;
//        boolean flag = true;
//        List<String> applyIdList = new ArrayList<>();
        if (!StringUtils.isEmpty(briTrainTicketDTO.getRelateYBZID())) {
//            HashMap<String, Object> paramMap = new HashMap<>();
//            applyIdList.clear();
//            applyIdList.add(briTrainTicketDTO.getRelateYBZID());
//            paramMap.put("tenant", tenant);
//            paramMap.put("pagenum", 10);
//            paramMap.put("pks", applyIdList);
//            //暂时没传电话
//            String phone = "";
//            while (flag) {
//                paramMap.put("page", page++);
//                HashMap<String, String> headers = new HashMap<>();
//                headers.put("Content-Type", "application/json");
//                String res = HttpClientUtil.post(URL + "?phone=" + phone + "&loginType=1&tenantId=" + tenant, headers, null, JSON.toJSONString(paramMap));
//                JSONObject resObject = JSON.parseObject(res);
//                if (resObject.getBoolean("success") && "1".equals(resObject.getString("code"))) {
//                    if (resObject.getJSONArray("data") != null && !resObject.getJSONArray("data").isEmpty()) {
//                        for (int i = 0; i < resObject.getJSONArray("data").size(); i++) {
//                            JSONObject data = resObject.getJSONArray("data").getJSONObject(i);
//                            if (data.getBoolean("success")) {
//                                JSONArray heads = data.getJSONArray("head");
//                                if (heads != null) {
//                                    for (Object head : heads) {
//                                        JSONObject headJsonObject = (JSONObject) head;
//                                        if (BriTrainOrder.ASSUME_ORG.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            //若能获取到翻译结果，则显示翻译结果；若获取不到，则显示保存时的name值
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briTrainTicketDTO.setAssumeOrg(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithAssumeOrgTrain(briTrainTicketDTO);
//                                            }
//                                        }
//                                        if (BriTrainOrder.ASSUME_DEPT.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briTrainTicketDTO.setAssumeDept(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithAssumeDeptTrain(briTrainTicketDTO);
//                                            }
//                                        }
//                                        if (BriTrainOrder.COST_PROJECT.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briTrainTicketDTO.setCostProject(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithCostProjectTrain(briTrainTicketDTO);
//                                            }
//                                        }
//                                        if (BriTrainOrder.APPLY_USER.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briTrainTicketDTO.setApplyUser(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithApplyUserTrain(briTrainTicketDTO);
//                                            }
//                                        }
//                                        if (BriTrainOrder.COMPANION.equals(headJsonObject.getString("source_code"))) {
//                                            if (headJsonObject.get("source_value") instanceof String && !StringUtils.isEmpty(headJsonObject.getString("source_value"))) {
//                                                briTrainTicketDTO.setCompanion(headJsonObject.getString("source_value"));
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    } else {
//                        dealWithAssumeOrgTrain(briTrainTicketDTO);
//                        dealWithAssumeDeptTrain(briTrainTicketDTO);
//                        dealWithCostProjectTrain(briTrainTicketDTO);
//                        dealWithApplyUserTrain(briTrainTicketDTO);
//                    }
//                    //最后一页跳出循环
//                    if (resObject.getInteger("totalPage") < page) {
//                        flag = false;
//                    }
//                } else {
//                    flag = false;
                    dealWithAssumeOrgTrain(briTrainTicketDTO);
                    dealWithAssumeDeptTrain(briTrainTicketDTO);
                    dealWithCostProjectTrain(briTrainTicketDTO);
                    dealWithApplyUserTrain(briTrainTicketDTO);
//                }
//            }
        }
    }

    private static void dealWithApplyUserTrain(BriTrainTicketDTO briTrainTicketDTO) {
        if (!StringUtils.isEmpty(briTrainTicketDTO.getApplyUser()) && briTrainTicketDTO.getApplyUser().contains(",")) {
            String[] split = briTrainTicketDTO.getApplyUser().split(",");
            if (split.length > 1) {
                briTrainTicketDTO.setApplyUser(split[1]);
            }
        }
    }

    private static void dealWithCostProjectTrain(BriTrainTicketDTO briTrainTicketDTO) {
        if (!StringUtils.isEmpty(briTrainTicketDTO.getCostProject()) && briTrainTicketDTO.getCostProject().contains(",")) {
            String[] split = briTrainTicketDTO.getCostProject().split(",");
            if (split.length > 1) {
                briTrainTicketDTO.setCostProject(split[1]);
            }
        }
    }

    private static void dealWithAssumeDeptTrain(BriTrainTicketDTO briTrainTicketDTO) {
        if (!StringUtils.isEmpty(briTrainTicketDTO.getAssumeDept()) && briTrainTicketDTO.getAssumeDept().contains(",")) {
            String[] split = briTrainTicketDTO.getAssumeDept().split(",");
            if (split.length > 1) {
                briTrainTicketDTO.setAssumeDept(split[1]);
            }
        }
    }

    private static void dealWithAssumeOrgTrain(BriTrainTicketDTO briTrainTicketDTO) {
        if (!StringUtils.isEmpty(briTrainTicketDTO.getAssumeOrg()) && briTrainTicketDTO.getAssumeOrg().contains(",")) {
            String[] split = briTrainTicketDTO.getAssumeOrg().split(",");
            if (split.length > 1) {
                briTrainTicketDTO.setAssumeOrg(split[1]);
            }
        }
    }

    public static BriCarOrderDTO perfactCarDTO(BriCarOrderDTO briCarOrderDTO) {
        if (briCarOrderDTO == null) {
            return null;
        }
        briCarOrderDTO.setFromType(fromTypeName(briCarOrderDTO.getFromType()));
        briCarOrderDTO.setType(carTypeName(briCarOrderDTO.getType()));
        briCarOrderDTO.setPublicOrPrivate(publicOrPrivateName(briCarOrderDTO.getPublicOrPrivate()));
        briCarOrderDTO.setIsDomc(isDomicName(briCarOrderDTO.getIsDomc()));
        briCarOrderDTO.setOrderStatus(carOrderStatusName(briCarOrderDTO.getOrderStatus()));
        briCarOrderDTO.setPayType(payTypeName(briCarOrderDTO.getPayType()));
        briCarOrderDTO.setBxState(bxStatusName(briCarOrderDTO.getBxState()));
        briCarOrderDTO.setIsNote(isNoteName(briCarOrderDTO.getIsNote()));
        dealWithApplyCar(briCarOrderDTO.getTenant(), briCarOrderDTO);
        return briCarOrderDTO;
    }

    private static void dealWithApplyCar(String tenant, BriCarOrderDTO briCarOrderDTO) {
//        int page = 1;
//        boolean flag = true;
//        List<String> applyIdList = new ArrayList<>();
        if (!StringUtils.isEmpty(briCarOrderDTO.getInApproveId())) {
//            HashMap<String, Object> paramMap = new HashMap<>();
//            applyIdList.clear();
//            applyIdList.add(briCarOrderDTO.getInApproveId());
//            paramMap.put("tenant", tenant);
//            paramMap.put("pagenum", 10);
//            paramMap.put("pks", applyIdList);
//            //暂时没传电话
//            String phone = "";
//            while (flag) {
//                paramMap.put("page", page++);
//                HashMap<String, String> headers = new HashMap<>();
//                headers.put("Content-Type", "application/json");
//                String res = HttpClientUtil.post(URL + "?phone=" + phone + "&loginType=1&tenantId=" + tenant, headers, null, JSON.toJSONString(paramMap));
//                JSONObject resObject = JSON.parseObject(res);
//                if (resObject.getBoolean("success") && "1".equals(resObject.getString("code"))) {
//                    if (resObject.getJSONArray("data") != null && !resObject.getJSONArray("data").isEmpty()) {
//                        for (int i = 0; i < resObject.getJSONArray("data").size(); i++) {
//                            JSONObject data = resObject.getJSONArray("data").getJSONObject(i);
//                            if (data.getBoolean("success")) {
//                                JSONArray heads = data.getJSONArray("head");
//                                if (heads != null) {
//                                    for (Object head : heads) {
//                                        JSONObject headJsonObject = (JSONObject) head;
//                                        if (BriCarOrder.ASSUME_ORG.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            //若能获取到翻译结果，则显示翻译结果；若获取不到，则显示保存时的name值
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briCarOrderDTO.setAssumeOrg(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithAssumeOrgCar(briCarOrderDTO);
//                                            }
//                                        }
//                                        if (BriCarOrder.ASSUME_DEPT.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briCarOrderDTO.setAssumeDept(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithAssumeDeptCar(briCarOrderDTO);
//                                            }
//                                        }
//                                        if (BriCarOrder.COST_PROJECT.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briCarOrderDTO.setCostProject(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithCostProjectCar(briCarOrderDTO);
//                                            }
//                                        }
//                                        if (BriCarOrder.APPLY_USER.equals(headJsonObject.getString("source_code")) && headJsonObject.get("source_value") != null) {
//                                            if (headJsonObject.get("source_value") instanceof JSONObject && !StringUtils.isEmpty(headJsonObject.getJSONObject("source_value").getString("name"))) {
//                                                briCarOrderDTO.setApplyUser(headJsonObject.getJSONObject("source_value").getString("name"));
//                                            } else {
//                                                dealWithApplyUserCar(briCarOrderDTO);
//                                            }
//                                        }
//                                        if (BriCarOrder.COMPANION.equals(headJsonObject.getString("source_code"))) {
//                                            if (headJsonObject.get("source_value") instanceof String && !StringUtils.isEmpty(headJsonObject.getString("source_value"))) {
//                                                briCarOrderDTO.setCompanion(headJsonObject.getString("source_value"));
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    } else {
//                        dealWithAssumeOrgCar(briCarOrderDTO);
//                        dealWithAssumeDeptCar(briCarOrderDTO);
//                        dealWithCostProjectCar(briCarOrderDTO);
//                        dealWithApplyUserCar(briCarOrderDTO);
//                    }
//                    //最后一页跳出循环
//                    if (resObject.getInteger("totalPage") < page) {
//                        flag = false;
//                    }
//                } else {
//                    flag = false;
                    dealWithAssumeOrgCar(briCarOrderDTO);
                    dealWithAssumeDeptCar(briCarOrderDTO);
                    dealWithCostProjectCar(briCarOrderDTO);
                    dealWithApplyUserCar(briCarOrderDTO);
//                }
//            }
        }
    }

    private static void dealWithApplyUserCar(BriCarOrderDTO briCarOrderDTO) {
        if (!StringUtils.isEmpty(briCarOrderDTO.getApplyUser()) && briCarOrderDTO.getApplyUser().contains(",")) {
            String[] split = briCarOrderDTO.getApplyUser().split(",");
            if (split.length > 1) {
                briCarOrderDTO.setApplyUser(split[1]);
            }
        }
    }

    private static void dealWithCostProjectCar(BriCarOrderDTO briCarOrderDTO) {
        if (!StringUtils.isEmpty(briCarOrderDTO.getCostProject()) && briCarOrderDTO.getCostProject().contains(",")) {
            String[] split = briCarOrderDTO.getCostProject().split(",");
            if (split.length > 1) {
                briCarOrderDTO.setCostProject(split[1]);
            }
        }
    }

    private static void dealWithAssumeDeptCar(BriCarOrderDTO briCarOrderDTO) {
        if (!StringUtils.isEmpty(briCarOrderDTO.getAssumeDept()) && briCarOrderDTO.getAssumeDept().contains(",")) {
            String[] split = briCarOrderDTO.getAssumeDept().split(",");
            if (split.length > 1) {
                briCarOrderDTO.setAssumeDept(split[1]);
            }
        }
    }

    private static void dealWithAssumeOrgCar(BriCarOrderDTO briCarOrderDTO) {
        if (!StringUtils.isEmpty(briCarOrderDTO.getAssumeOrg()) && briCarOrderDTO.getAssumeOrg().contains(",")) {
            String[] split = briCarOrderDTO.getAssumeOrg().split(",");
            if (split.length > 1) {
                briCarOrderDTO.setAssumeOrg(split[1]);
            }
        }
    }
}

